from time import sleep

import yaml
from selenium import webdriver


class TestGetCookiesBySleep():
    def setup(self):
        self.driver = webdriver.Chrome()

    # def teardown(self):
    #     self.driver.quit()

    def test_get_cookies_by_sleep(self):
        self.driver.get("https://work.weixin.qq.com/wework_admin/loginpage_wx?from=myhome")
        sleep(10)
        cookies = self.driver.get_cookies()
        with open("D:/Study/git/WeComWebTest/data/cookies.yaml", "w", encoding="utf-8") as f:
            yaml.dump(cookies, f)

    def test_cookies(self):
        # 先打开企业微信的页面，才能传cookies进去
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
        cookie = yaml.safe_load(open("D:/Study/git/WeComWebTest/data/cookies.yaml"))
        for c in cookie:
            self.driver.add_cookie(c)
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
        sleep(2)